package hrm.action.org;

import hrm.action.Action;
import hrm.action.ActionForward;
import hrm.dto.org.OrgBaseDTO;
import hrm.dto.org.TreeDTO;
import hrm.serviceimple.OrgServiceImple;

import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class OrgBeforeBaseUpdateAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		ActionForward actfoward = new ActionForward();
		OrgServiceImple orgService = OrgServiceImple.getInstance();
		String sdate;
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH)+1;
		int date = cal.get(Calendar.DATE);
		sdate = (year+"-"+month+"-"+date);
		String updateorgcode = request.getParameter("updateorgcode");

		String orgcode = request.getParameter("code");
		List<TreeDTO> treelist = orgService.getOrgtree(sdate);
		OrgBaseDTO dto = orgService.getOrgbase(orgcode);
		String orgtree = orgService.getMenuTreeString(sdate).toString(); 
		String orguppername; 
		if(dto.getOrgcode().equals("01000000")){
			orguppername = "";			
		} else {
			orguppername = orgService.getOrgbase(dto.getOrguppercode()).getOrgname();			
		}
		OrgBaseDTO orgbase = orgService.getOrgbase(updateorgcode);
		request.setAttribute("orguppername", orguppername);
		request.setAttribute("treelist", treelist);
		request.setAttribute("orgtree", orgtree);
		request.setAttribute("code", orgcode);
		request.setAttribute("orgbaseinfo", dto);
		request.setAttribute("orgbase", orgbase);
		request.setAttribute("sdate", sdate);
		actfoward.setUrl("orgbaseupdate");
		return actfoward;
	}

}
